'use strict';

const createValidate = {
  title: {
    type: 'string',
    min: 1,
    max: 40,
  },
  pic: {
    type: 'url',
  },
  detail: {
    type: 'string',
    max: 140,
    required: false,
  },
  switch: {
    type: 'string',
    max: 140,
    required: false,
  },
  index: {
    type: 'number',
    min: 0,
    max: 9,
  },
}

exports.create = async ctx => {
  ctx.validate(createValidate);
  ctx.sendSuccess(await ctx.service.banner.create());
};

exports.destroy = async ctx => {
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.banner.destroy());
};

exports.update = async ctx => {
  ctx.validate(createValidate);
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.banner.update());
};
